package com.daniu101.productbargan.smstest;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dysmsapi20170525.Client client = Sample.createClient("LTAI9Arxoq5xv4Pk", "EkwRPvg3TlQwHuVs5EbPAUscGrZlzH");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers("15235955637")
                .setSignName("副业君")
                .setTemplateCode("SMS_192542265")
                .setTemplateParam("{\"code\":\"123456\"}");
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse ssr = client.sendSms(sendSmsRequest);
        String codeRes = ssr.getBody().getCode();
        if ("OK".equals(codeRes)){
            System.out.println("发送成功");
        }else {
            System.out.println("发送失败");
        }
    }
}